package com.example.androidtvdemo.demo03;

import android.widget.Button;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.androidtvdemo.R;

import java.util.List;

public class TextAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

    private int position = -1;

    public TextAdapter() {
        super(R.layout.item_list_a_layout);
    }

    public void setPosition(int position) {
        this.position = position;
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        Button textView = helper.getView(R.id.tv_name_a);
        textView.setText(item);
        int adapterPosition = helper.getAdapterPosition();
        if (adapterPosition == 0) {
            textView.setNextFocusLeftId(textView.getId());
        }
        if (adapterPosition == getData().size() - 1) {
            textView.setNextFocusRightId(textView.getId());
        }
        //指定某个属性主动请求焦点
        if (position == adapterPosition) {
            textView.requestFocus();
        }
    }
}
